package com.decent.common.monitor.service.impl;

import com.decent.common.monitor.dao.SystemMonitorDao;
import com.decent.common.monitor.service.SystemMonitorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 运维系统监控Service实现类
 *
 * @author wangyan
 * @author 2022/04/07 9:20
 */
@Slf4j
@Service
public class SystemMonitorServiceImpl implements SystemMonitorService {
    private static final String HEART_BEAT_MONITOR_KEY = "heartBeatMonitor";
    @Resource
    private SystemMonitorDao systemMonitorDao;

    /**
     * 心跳监控
     * INSERT INTO tbl_system_monitor (monitor_key, monitor_value) VALUES ('heartBeatMonitor', 'normal');
     *
     * @return 数据库监控信息，正常返回：normal
     */
    @Override
    public String monitor() {
        try {
            return systemMonitorDao.monitor(HEART_BEAT_MONITOR_KEY);
        } catch (Exception e) {
            log.error("运维心跳监控异常", e);
            return "error";
        }
    }
}

